<?php

/**
 * Controller_student
 * 学生、年级、班级、学科、二维码
 */

class Controller_student extends MyApp {

	public function __construct()
	{
		parent::__construct();

		$this->model->record 	= YOU::loadModel('record');
		$this->model->user   	= YOU::loadModel('user');
		$this->model->class  	= YOU::loadModel('class');
		$this->model->excel  	= YOU::loadModel('excel');
		$this->model->subject  	= YOU::loadModel('subject');
		$this->model->grade  	= YOU::loadModel('grade');
		$this->model->student  	= YOU::loadModel('student');
	}
	/** 首页 **/
	public function actionIndex()
	{

	}
	//**---------------------------------- 学生------------------------------**//

	/** 二级联动 **/
	public function actionListJson ()
	{
		$class_id = (int)$this->get->class_id;
		if (!empty($class_id)) {
			$student_lists = $this->db->fetchAll("SELECT * FROM `tbl_student` WHERE class_id='{$class_id}'");
			foreach ($student_lists as $key => $value){
				$student_lists[$key]['student_sex'] = $this->sex_ini[$value['student_sex']];
			}
		}

		if(!empty($student_lists)){
			echo json_encode($student_lists);
		}else{
			exit("0");
		}
	}
	/** 二级联动(学生分类) **/
	public function actionStateJson ()
	{
		$student_state = (int)$this->get->student_state;

		// student_state=1复读生 ，2=转入生， 0=其他
		if ($student_state ==1) {

			$student_lists = $this->db->fetchAll("SELECT * FROM `tbl_student` WHERE student_variation='复学' AND class_id ='0'");
		}
		if ($student_state ==2) {
			$student_lists = $this->db->fetchAll("SELECT * FROM `tbl_student` WHERE student_variation='转入' AND class_id ='0'");
		}
		if ($student_state ==0) {
			$student_lists = $this->db->fetchAll("SELECT * FROM `tbl_student` WHERE student_variation !='转入'AND student_variation !='复学' AND class_id ='0'");
		}

		foreach ($student_lists as $key=>$value){
			$student_lists[$key]['student_sex'] = $this->sex_ini[$value['student_sex']];
		}
		if(!empty($student_lists)){
			echo json_encode($student_lists);
		}else{
			exit("0");
		}
	}
	/** 二级联动(年级) **/
	public function actionGradeJson ()
	{
		$grade_id = (int)$this->get->grade_id;
		if (!empty($grade_id)) {
			$student_lists = $this->db->fetchAll("SELECT * FROM `tbl_student` WHERE grade_id='{$grade_id}'");
		}

		if(!empty($student_lists)){
			echo json_encode($student_lists);
		}else{
			exit("0");
		}
	}
	/** 二级联动 --班級->年級**/
	public function actionGradeListJson ()
	{
		$grade_id = (int)$this->get->grade_id;
		if (!empty($grade_id)) {
			$grade_lists = $this->model->class->getListByGrade($grade_id);

		}

		if(!empty($grade_lists)){
			echo json_encode($grade_lists);
		}else{
			exit("0");
		}
	}

	/** 学生管理列表 **/
	public function actionStudentList ()
	{	
		//按条件搜索
		$where = "WHERE 1=1";

		//获取到页面传过来的要搜索的条件
		$student_no   = (int)$this->get->student_no;
		$student_name = $this->get->student_name;

		if (!empty($student_no)) {
			$where .= " AND student_no='{$student_no}' ";
			$this->tpl->assign("student_no", $student_no);
		}
		if (!empty($student_name)) {
			$where .= " AND student_name LIKE '%{$student_name}%' ";
			$this->tpl->assign("student_name", $student_name);
		}
		
		if ($where != "WHERE 1=1") {
			
			$student_lists = $this->db->fetchAll("SELECT * FROM `tbl_student` {$where} ORDER BY student_id DESC ");
		}
		
		// 性别、残疾、户口性质、
        if(is_array($student_lists)){
            foreach($student_lists as $key => $value){
                // 性别
                $student_lists[$key]['student_sex']        = $this->sex_ini[$value['student_sex']];
                // 残疾
                $student_lists[$key]['student_disability'] = $this->disability_ini[$value['student_disability']];
                // 学生类别
                $student_lists[$key]['student_mode']    = $this->classes_ini[$value['student_mode']];
                // 学生户口性质
                $student_lists[$key]['student_registered'] = $this->registered_ini[$value['student_registered']];
            }
        }


		$this->tpl->assign("student_lists", $student_lists);
		$this->tpl->display('student/m.basic.list.tpl.php');

	}

	/*
	* 导出数据
	*/
	public function actionOutData()
	{

		$student_lists = $this->db->fetchAll("SELECT * FROM `tbl_student`  ORDER BY grade_id DESC ");

		$rule = $this->model->record->getInfo('student_list');
		$col = array();
		foreach($rule as $k => $v){
			$col[] = $v['title'];
		}
		//var_dump($arr);exit;
		//$data_lists['0'] = $col;
		$info = array();

		foreach ($student_lists as $key => $value) {
			$i = 0;
			foreach ($rule as $k => $v){

				// $arr[] = $v['name'];
				//var_dump($v['student_start_time']);exit;
				switch ($v['name']){
					case  'is_work':
						$info[$i] = $this->yes_ini[$value[$v['name']]];
						break;
					case  'student_over':
						$info[$i] = $this->yes_ini[$value[$v['name']]];
						break;
					case  'is_alone':
						$info[$i] = $this->yes_ini[$value[$v['name']]];
						break;
					case  'is_study':
						$info[$i] = $this->yes_ini[$value[$v['name']]];
						break;
					case  'is_stay':
						$info[$i] = $this->yes_ini[$value[$v['name']]];
						break;
					case  'is_help':
						$info[$i] = $this->yes_ini[$value[$v['name']]];
						break;
					case  'is_martyr':
						$info[$i] = $this->yes_ini[$value[$v['name']]];
						break;
					case  'is_left':
						$info[$i] = $this->yes_ini[$value[$v['name']]];
						break;
					case  'is_subsidy':
						$info[$i] = $this->yes_ini[$value[$v['name']]];
						break;
					case  'student_sex':
						$info[$i] = $this->sex_ini[$value[$v['name']]];
						break;

					case  'student_ctime':
						$info[$i] = $value[$v['name']];
						break;
					case  'student_start_time':
						$info[$i] = date('Y-m',strtotime($value[$v['name']]));
						break;
					case  'student_card':
						$info[$i] =  ' '.$value[$v['name']];
						break;
					case  'student_card':
						$info[$i] =  ' '.$value[$v['name']];
						break;
					case  'student_birth':
						$info[$i] =  ' '.$value[$v['name']];
						break;
					case  'student_school':
						$info[$i] =  ' '.$value[$v['name']];
						break;
					case  'student_no':
						$info[$i] =  ' '.$value[$v['name']];
						break;
					case  'student_disability':
						$info[$i] = $this->disability_ini[$value[$v['name']]];
						break;
					case  'student_registered':
						$info[$i] = $this->registered_ini[$value[$v['name']]];
						break;
					case  'student_mode':
						$info[$i] = $this->mode_ini[$value[$v['name']]];
						break;
					case  'student_classes':
						$info[$i] = $this->classes_ini[$value[$v['name']]];
						break;
					case  'student_state':
						$info[$i] = $this->state_ini[$value[$v['name']]];
						break;
					case  'student_type':
						$info[$i] = $this->etype_ini[$value[$v['name']]];
						break;
					case  'grade_id':
						$grade_data = $this->db->fetchRow("select grade_name from tbl_grade WHERE grade_id = '{$value[$v['name']]}'") ;

						$info[$i] = $grade_data['grade_name'];
						break;
					case  'class_id':
						$class_data = $this->db->fetchRow("select class_name from tbl_class WHERE class_id = '{$value[$v['name']]}'") ;

						$info[$i] = $class_data['class_name'];
						break;

					default:
						$info[$i] = $value[$v['name']];
				}
				$i++;

			}
			$data_lists[$key] = $info;



		}
		//var_dump($data_lists);exit;
		// 模板标题
		$this->model->excel->excel_ini['studentcount']['title'] = "学生统计表";
		$this->model->excel->excel_ini['studentcount']['col'] = $col;
		$this->model->excel->outData("studentcount", $data_lists);

		//$this->tpl->display();
	}
	/** 学生管理其他列表 **/
	public function actionStudentRestsList ()
	{
		//按条件搜索
		$where = "WHERE 1=1";

		//获取到页面传过来的要搜索的条件
		$student_no   = (int)$this->get->student_no;
		$student_name = $this->get->student_name;

		if (!empty($student_no)) {
			$where .= " AND student_no='{$student_no}' ";
			$this->tpl->assign("student_no", $student_no);
		}
		if (!empty($student_name)) {
			$where .= " AND student_name LIKE '%{$student_name}%' ";
			$this->tpl->assign("student_name", $student_name);
		}
		
		if ($where !="WHERE 1=1") {
			$student_lists = $this->db->fetchAll("SELECT * FROM `tbl_student` {$where}ORDER BY student_id DESC ");
		}
		
		// 性别、残疾、户口性质、
		foreach($student_lists as $key => $value){
			// 性别
			$student_lists[$key]['student_sex'] = $this->sex_ini[$value['student_sex']];
			// 残疾
			$student_lists[$key]['student_disability'] = $this->disability_ini[$value['student_disability']];
			// 学生类别
			$student_lists[$key]['student_mode'] = $this->classes_ini[$value['student_mode']];
			// 学生户口性质
			$student_lists[$key]['student_registered'] = $this->registered_ini[$value['student_registered']];
			$student_lists[$key]['student_mode']  = $this->mode_ini[$value['student_mode']];
		}

		
		$this->tpl->assign("student_lists", $student_lists);
		$this->tpl->display('student/m.rests.list.tpl.php');

	}



	/** 批量导入学生信息 **/
	public function actionIn()
	{

		//echo date('Y-m-d',strtotime('12-11'));echo 123;


		//set_time_limit(3600);


		if($_POST){


			$check = $this->post->check;


			if($check!=='del'&&$check!=='add'){

				$data = $this->model->excel->in('studentcount');
                $mes = '';
				foreach ($data as $k => $v){
					$student_card = $v['3'];
					$row = $this->db->fetchRow("SELECT student_card FROM `tbl_student` WHERE student_card='{$student_card}' ");
					if (!empty($row)) {
						$mes .= "学生信息已存在，身份证号码为： {$student_card}<br>";
						$check = 2;

					}

				}
                $this->tpl->assign("mes", $mes);
                //$this->tpl->assign("student_card", $student_card);
                $this->tpl->assign("check", $check);
                $this->tpl->display("student/student.in.tpl.php");
                exit;
			}
//			else{
//				$data = $this->model->excel->in('studentcount', "in");
//			}
            if($check=='del'){
                $data = $this->model->excel->in('studentcount',2);
                foreach ($data as $k => $v){
                    $student_card = $v['3'];
                    $sid = $this->db->query("DELETE  FROM `tbl_student` WHERE student_card='{$student_card}'");
                    $this->model->user->getDel($sid, "student");
                }
            }elseif($check=='add'){
                $data = $this->model->excel->in('studentcount',2);
            }


			if(empty($data)){
				Helper_Client::alert("请上传文件");
			}

			foreach ($data as $key => $value){

				$grade_data = $this->db->fetchRow("select grade_id from tbl_grade WHERE grade_name like '%{$value[23]}%'") ;
				$value[23] = $grade_data['grade_id'];
				$class_data = $this->db->fetchRow("select class_id from tbl_class WHERE class_name like '%{$value[25]}%' AND grade_id ={$grade_data['grade_id']}") ;
				$value[25] = $class_data['class_id'];
				//echo date('Y-m-d',strtotime($value[19]));exit;
				//$value[25]//class
				//c_time  start_time   yunhui
				if(preg_match('/\d{2}\.\d{2}/',$value[11],$m)){
					$value[11] = '20'.str_replace('.','-',$value[11]);

				}elseif (preg_match('/\d{4}\.\d{2}/',$value[11],$m)){
					$value[11] = str_replace('.','-',$value[11]);

				}
				elseif (preg_match('/\d{2}\.\d{2}/',$value[11],$m)){
					$value[11] = str_replace('.','-',$value[11]);

				}
				elseif(preg_match('/\d{2}\-\d{2}/',$value[11],$m)){
					$value[11] = '20'.$value[11];

				};
				//echo date('Y-m-d',strtotime($value[19]));exit;
				if(in_array($value[49],$this->disability_ini)){
					$arr = array_flip($this->disability_ini);
					$value[49] = $arr[$value[49]];
				}else{$value[49] = 0;}


				//$birth     = $value[19];
				//$value[19] = substr($birth, 0, 5).'-'.substr($birth, 5, 2).'-'.substr($birth, 7, 2);
				$info = array(
				"student_name"           => $value[1],
				"student_school"         => $value[2],
				"student_card"           => $value[3],
				"student_sex"            => $value[4]=='男'?1:0,
				"student_no"             => trim($value[5]),
				"student_register"       => $value[6],//
				"student_office"         => $value[7],
				"student_islocal"        => $value[8],
				"student_over"           => $value[9]=='否'?0:1,
				"student_variation"      => $value[10],//biandong
				"student_ctime"          => date('Y-m',strtotime($value[11])),//$value[11],//
				"student_remarks"        => $value[12],
				"student_native"         => $value[13],//jiguan
				"student_nation"         => $value[14],//
				"student_addr"           => $value[15], // add 20161105
				"student_tel"            => trim($value[16]),
				"student_sname"          => $value[17],//xuexiaoming
				"student_snumber"        => $value[18],// no
				"student_birth"          => date('Y-m-d',strtotime($value[19])),//
				"student_city"           => $value[20],//place
				"student_country"        => $value[21],
				"student_idtype"         => $value[22],
				"grade_id"               => $value[23],//                           nianji
				"student_china"          => $value[24],
				"class_id"               => $value[25],//                    banji
				"student_politics"       => $value[26],//nature
				"student_health"         => $value[27],
				"student_register_place" => $value[28],//hukou suozai
				"student_registered"     => $value[29]=='农村'?1:2,//hukou xingzhi        aaaaaaaaa
				"student_start_time"     => date('Y-m-d',strtotime($value[30])),//ruxue date
				"student_now_addr"       => ''.$value[31],
				"student_way"            => ''.$value[32],
				"student_tel_addr"       => $value[33],
				"student_home_addr"      => $value[34],
				"student_mail"           => ''.$value[35],
				"is_work"                => $value[36]=='否'?0:1,
				"is_alone"               => $value[37]=='否'?0:1,
				"is_study"               => $value[38]=='否'?0:1,//aaa
				"is_stay"                => $value[39]=='否'?0:1,
				"is_help"                => $value[40]=='否'?0:1,
				"is_martyr"              => $value[41]=='否'?0:1,
				"is_subsidy"             => $value[42]=='否'?0:1,
				"student_mode"           => $value[43]=='寄宿'?1:0,// jiudu fangshiaaa
				"is_left"                => $value[44]=='否'?0:1,
				"student_help_no"        => ''.$value[45],
				"student_class_no"       => ''.$value[46],
				"student_from"           => $value[47],
				"student_read"           => $value[48],//suiban
				"student_disability"     => $value[49],//
				"student_parent"         => $value[50],
				"student_home_relation"  => $value[51],
				"student_home_work"      => $value[52],
				"student_parent_addr"    => $value[53],
				"student_ptel"           => ' '.$value[54],
				"student_parent_city"    => $value[55],//huji
				"create_time"       => date("Y-m-d",time()),
				);
				//echo $value['11'];exit;
//				$student_card = $value['3'];
//				$row = $this->db->fetchRow("SELECT student_card FROM `tbl_student` WHERE student_card='{$student_card}' ");
//				if (!empty($row)) {
//					$this->db->do_update("tbl_student", $info, "student_card='{$student_card}'" );
//				}else{
					$this->model->user->add("student", $info);
				//}

			}
			// 跳转
			Helper_Client::location("添加成功", "index.php?a=student.studentlist");


		}

		$this->tpl->display("student/student.in.tpl.php");
	}

	/** 学生添加 **/
	public function actionstudentAdd()
	{

		if ($_POST){

			$student_name     	    = $this->post->student_name;
			$student_sex     	    = $this->post->student_sex;
			$student_birth     	    = $this->post->student_birth;
			$student_card     	    = $this->post->student_card;
			$student_nation     	= $this->post->student_nation;
			$student_registered     = $this->post->student_registered;
			$student_tel     	    = $this->post->student_tel;
			$student_no     	    = $this->post->student_no;
			$student_source     	= $this->post->student_source;
			$student_school     	= $this->post->student_school;
			$student_variation     	= $this->post->student_variation;
			$student_mode     		= $this->post->student_mode;
			$student_mode        	= $this->post->student_mode;
			$student_disability     = $this->post->student_disability;


			// 学号唯一不能重复添加
			$student_no = $this->db->fetchRow("SELECT * FROM `tbl_student` WHERE student_no={$student_no}");
			// 学籍号唯一不能重复添加
			$student_school = $this->db->fetchRow("SELECT * FROM `tbl_student` WHERE student_school={$student_school}");
			// 学籍号唯一不能重复添加
			$student_card = $this->db->fetchRow("SELECT * FROM `tbl_student` WHERE student_card={$student_card}");
			if(!empty($student_no)){
				Helper_Client::alert("学号已存在");
			}
			if(!empty($student_school)){
				Helper_Client::alert("全国学籍已存在");
			}
			if(!empty($student_card)){
				Helper_Client::alert("身份证已存在");
			}
			// 写入数据库
			$info = array(

			"student_name"      	=> $student_name,
			"student_sex"			=> $student_sex,
			"student_birth"      	=> $student_birth,
			"student_card"      	=> $student_card,
			"student_nation"      	=> $student_nation,
			"student_registered"    => $student_registered,
			"student_tel"			=> $student_tel,
			"student_no"			=> $student_no,
			"student_source"      	=> $student_source,
			"student_school"      	=> $student_school,
			"student_variation"     => $student_variation,
			"student_mode"      	=> $student_mode,
			"student_mode"      	=> $student_mode,
			"student_disability"    => $student_disability,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",

			);

			$this->model->user->add("student", $info);

			// 跳转
			Helper_Client::location("添加成功", "index.php?a=student.studentlist&student_id={$student_id}");
		}

		$this->tpl->display('student/student.add.tpl.php');
	}
	/** 修改学生资料 **/
	public function actionstudentUpdate()
	{

		$student_id   = (int)$this->get->student_id;
		$student_data = $this->db->fetchRow("SELECT * FROM `tbl_student` WHERE `student_id`='{$student_id}'");
		$sv = $student_data['student_variation'];
		if (empty($student_data)){
			Helper_Client::alert("学生不存在");
		}

		if ($_POST){

			$student_name     	    = $this->post->student_name;
			$student_sex     	    = $this->post->student_sex;
			$student_birth     	    = $this->post->student_birth;
			$student_card     	    = $this->post->student_card;
			$student_nation     	= $this->post->student_nation;
			$student_registered     = $this->post->student_registered;
			$student_tel     	    = $this->post->student_tel;
			$student_no     	    = $this->post->student_no;
			$student_source     	= $this->post->student_source;
			$student_school     	= $this->post->student_school;
			$student_variation     	= $this->post->student_variation;
			//$student_mode     	= $this->post->student_mode;
			$student_mode        	= $this->post->student_mode;
			$student_disability     = $this->post->student_disability;
			if($student_variation!=$sv){
				$info = array(
				'student_id'    => $student_id,
				'schange_time'  =>date("Y-m-d H:i:s"),
				'student_variation'   =>$student_variation,
				'create_time'  =>date("Y-m-d H:i:s"),
				);
				$this->db->do_insert("tbl_schange", $info);
			}

			// 不能重复学号 修改
			$stu_data = $this->db->fetchRow("SELECT * FROM `tbl_student` WHERE student_no='{$student_no}'");
			if (!empty($stu_data)&& $student_data['student_no'] != $student_no){
				Helper_Client::alert("学号已存在");
			}

			// 写入数据库
			$info = array(

			"student_name"      	=> $student_name,
			"student_sex"			=> $student_sex,
			"student_birth"      	=> $student_birth,
			"student_card"      	=> $student_card,
			"student_nation"      	=> $student_nation,
			"student_registered"    => $student_registered,
			"student_tel"			=> $student_tel,
			"student_no"			=> $student_no,
			"student_source"      	=> $student_source,
			"student_school"      	=> $student_school,
			"student_variation"     => $student_variation,
			//"student_mode"      	=> $student_mode,
			"student_mode"      	=> $student_mode,
			"student_disability"    => $student_disability,

			);
			$this->db->do_update("tbl_student", $info, "student_id='{$student_id}'");

			// 跳转
			Helper_Client::location("修改成功", "index.php?a=student.student	list&student_id={$student_id}");
		}

		$this->tpl->assign("student_data", $student_data);
		$this->tpl->display('student/student.update.tpl.php');
	}
	/** 删除学生资料 **/
	public function actionstudentDel()
	{
		$student_id = $this->get->student_id;
		$this->db->query("DELETE  FROM `tbl_student` WHERE student_id='{$student_id}'");
		// 删除user表
		$this->model->user->getdel($student_id,'student');
		// 跳转
		Helper_Client::location("删除成功", "index.php?a=student.studentlist");
	}
	//**------------------------------------- 年级 -------------------------------**//
	/** 年级列表 **/
	public function actiongradeList()
	{
		// 最大grade_code
		$grade_max = $this->model->grade->getMaxCode();
		// 分页
		YOU::loadLib('page', "", '0');
		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_grade_up` WHERE is_now ='1'");
		$count = $tmp['count'];
		$page_total = ceil($count/PAGE_LIMIT);
		// 当前页
		$p = intval($_GET['p']);
		if ($p == 0){
			$p  = 1;
		}
		if ($p > 1){
			$start = PAGE_LIMIT * ($p-1);
		}else{
			$start = 0;
		}

		$grade_lists = $this->db->fetchAll("SELECT * FROM `tbl_grade_up` WHERE is_now ='1'ORDER BY grade_code ASC LIMIT {$start}, ".PAGE_LIMIT."");
		foreach($grade_lists as $key=>$value){
			// 班级数量
			$grade_lists[$key]['class_count']= $this->model->class->countGread($value['grade_id']);

		}

		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
		$page->next_page   = '下一页>';
		$page->pre_page    = '<上一页';
		$page->style_path  = "static/page_style";
		$this->tpl->assign("page", $page->show(4, "yahoo"));

		$this->tpl->assign("grade_lists", $grade_lists);
		$this->tpl->assign("grade_id", $grade_id);
		$this->tpl->assign("grade_max", $grade_max);
		$this->tpl->display('grade/grade.list.tpl.php');
	}

	/** 年级添加 **/
	public function actiongradeAdd()
	{
		if ($_POST){

			$grade_name     	    = $this->post->grade_name;
			$grade_xname     	    = $this->post->grade_xname;
			$grade_code    	        = $this->post->grade_code;
			$upg_year    	        = $this->post->upg_year;

			if (empty($upg_year)){
				Helper_Client::alert("请填写年级学年");
			}
			if (empty($grade_name)){
				Helper_Client::alert("请填写年级名称");
			}
			if (empty($grade_xname)){
				Helper_Client::alert("请填写年级代码");
			}
			if (empty($grade_code)){
				Helper_Client::alert("请填写年级简称");
			}

			// 写入数据库
			$info = array(

			"grade_name"      		=> $grade_name,
			"grade_xname"      		=> $grade_xname,
			"grade_code"      		=> $grade_code,
			"grade_type"  		    => $grade_type,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",

			);
			$this->db->do_insert("tbl_grade", $info);
			$grade_id = $this->db->insert_id();
			// 写入历史记录
			$info = array(

			"grade_id"      		=> $grade_id,
			"grade_name"      		=> $grade_name,
			"grade_xname"      		=> $grade_xname,
			"grade_code"      		=> $grade_code,
			"upg_fid"      			=> 0,
			"is_now"  		    	=> 1,
			"upg_year"  		    => $upg_year,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",

			);
			$this->db->do_insert("tbl_grade_up", $info);
			// 跳转
			Helper_Client::location("添加成功", "index.php?a=student.gradelist");
		}

		$this->tpl->display('grade/grade.add.tpl.php');

	}
	/** 年级修改 **/
	public function actiongradeUpdate()
	{

		$grade_id   	= (int)$this->get->grade_id;
		$grade_data 	= $this->model->grade->getInfo($grade_id);

		if (empty($grade_data)){
			Helper_Client::alert("年级不存在");
		}

		if ($_POST){

			$grade_name     	    = $this->post->grade_name;
			$grade_xname     	    = $this->post->grade_xname;
			$grade_code    	        = $this->post->grade_code;
			$upc_year   		    = $this->post->upc_year;

			// 写入数据库
			$info = array(

			"grade_name"      		=> $grade_name,
			"grade_xname"      		=> $grade_xname,
			"grade_code"      		=> $grade_code,
			"grade_year"  		    => $upc_year,
			"create_time"           => date("Y-m-d H:i:s"),

			);
			$this->db->do_update("tbl_grade", $info, "grade_id='{$grade_id}'");
			// 写入历史记录
			$info = array(

			"grade_name"      		=> $grade_name,
			"grade_xname"      		=> $grade_xname,
			"grade_code"      		=> $grade_code,
			"upg_year"  		    => $upc_year,
			"create_time"           => date("Y-m-d H:i:s"),

			);
			$this->db->do_update("tbl_grade_up", $info, "grade_id='{$grade_id}'");
			// 跳转
			Helper_Client::location("修改成功", "index.php?a=student.gradelist");
		}

		$this->tpl->assign("grade_data", $grade_data);
		$this->tpl->display('grade/grade.update.tpl.php');
	}
	/** 年级删除 **/
	public function actiongradeDel()
	{
		$grade_id = $this->get->grade_id;
		// 先判断是否有班级
		$row = $this->model->class->getListByGrade($grade_id);
		if (!empty($row)) {
			Helper_Client::alert("请先删除所有班级");
		}
		$this->db->query("DELETE  FROM `tbl_grade_up` WHERE grade_id='{$grade_id}' AND is_now='1'");
		$this->db->query("DELETE  FROM `tbl_grade` WHERE grade_id='{$grade_id}'");

		// 跳转
		Helper_Client::location("删除成功", "index.php?a=student.gradelist");
	}
	/** 学科分配 （年级）**/
	public function actiongradeallot()
	{
		$grade_id      = (int)$this->get->grade_id;
		// 年级
		$grade_data  	= $this->model->grade->getinfo($grade_id);
		// 班级
		$class_lists  	= $this->model->class->getListByGrade($grade_id);
		// 全部学科名称
		$subject_lists = $this->db->fetchAll("SELECT `subject_name`,`subject_id` FROM `tbl_subject`");

		if($_POST){

			$class_id	     	    = $this->post->class_id;
			$subject_id    			= $this->post->subject_id;
			// 学科
			$subject = array();
			foreach ($subject_id as $key => $value){

				$subject_name = $this->model->subject->getinfo($value);
				$subject[$value] = $subject_name['subject_name'];
			}

			// 序列化
			$class_subject = serialize($subject);

			foreach ($class_id as $key => $value){

				// 写入数据库
				$info = array(
				"class_subject"   	    => $class_subject,
				"update_time"           => date("Y-m-d H:i:s"),

				);

				$this->db->do_update("tbl_class_up", $info, "class_id='{$value}' AND is_now='1'");

			}

			// 跳转
			Helper_Client::location("分配成功", "index.php?a=student.gradelist");

		}
		$this->tpl->assign("grade_data", $grade_data);
		$this->tpl->assign("class_lists", $class_lists);
		$this->tpl->assign("subject_lists", $subject_lists);
		$this->tpl->display('grade/grade.allot.tbl.php');

	}
	//**------------------------------------ 班级 -----------------------------------**//
	/** 班级列表 **/
	public function actionclassList()
	{

		$grade_id		= (int)$this->get->grade_id;
		$subject_list   = $this->db->fetchAll("SELECT * FROM `tbl_subject`");
		// 所有的班级分类名称
		$classify_lists = $this->model->class->getclassifyall();

		// 分页
		YOU::loadLib('page', "", '0');
		$tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_class` AS a ,`tbl_class_up` AS b WHERE a.class_id=b.class_id  AND b.is_now =1 AND b.grade_id='{$grade_id}'");
		$count = $tmp['count'];
		$page_total = ceil($count/PAGE_LIMIT);
		// 当前页
		$p = intval($_GET['p']);
		if ($p == 0){
			$p  = 1;
		}
		if ($p > 1){
			$start = PAGE_LIMIT * ($p-1);
		}else{
			$start = 0;
		}

		$class_lists	= $this->db->fetchAll("SELECT * FROM `tbl_class_up` WHERE  is_now =1 AND grade_id='{$grade_id}' ORDER BY class_id ASC LIMIT {$start}, ".PAGE_LIMIT."");

		foreach($class_lists as $key => $value){
			// 班级学科
			$class_lists[$key]['class_subject'] =unserialize($value['class_subject']);
			// 班级分类
			$classify_data = $this->model->class->getClassifyinfo($value['classify_id']);
			$class_lists[$key]['classify_name'] = $classify_data['classify_name'];

		}

		if ($_POST){

			$class_id     	   	= $this->post->class_id;
			$classify_id     	= $this->post->classify_id;
			if(!empty($class_id)){

				// 批量添加班级科别
				foreach($class_id as $key=>$value){

					// 写入数据库
					$info = array(

					"classify_id"   		=> $classify_id,
					"status"                => 1,
					"create_time"           => date("Y-m-d H:i:s"),
					"update_time"           => "0000-00-00 00:00:00",

					);

					$this->db->do_update("tbl_class_up", $info, "class_id='$value' AND is_now='1'");

				}
				// 跳转
				Helper_Client::location("设置成功", "index.php?a=student.classlist&class_id={$class_id}&grade_id={$grade_id}");

			}
		}

		$page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
		$page->next_page   = '下一页>';
		$page->pre_page    = '<上一页';
		$page->style_path  = "static/page_style";

		$this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("grade_id", $grade_id);
		$this->tpl->assign("class_level", $class_level);
		$this->tpl->assign("subject_list", $subject_list);

		$this->tpl->assign("class_lists", $class_lists);
		$this->tpl->assign("classify_lists", $classify_lists);
		$this->tpl->display('class/class.list.tpl.php');

	}

	/** 班级批量生成 **/
	public function actionclassbatch()
	{
		$grade_id      = (int)$this->get->grade_id;
		// 年级
		$grade_date = $this->model->grade->getInfo($grade_id);

		if ($_POST){

			$class_count   = $this->post->class_count;
			// 取得当前班级最大数
			$row = $this->model->class->getClassBox($grade_id);
			$max_class = (int)$row['class_box']+1;
			$class_count = $max_class+$class_count;

			for ($i=$max_class;$i<$class_count;$i++){

				if($i < 9){
					$ii =$i;
					$i='0'.$i;
				}else{
					$ii =$i;
					$i=$i;
				}
				// 写入数据库
				$info = array(
				"class_box"      		=> $i,
				"class_name"      		=> $grade_date['grade_xname'].$ii.'班',
				"class_xname"      		=> $ii.'班',
				"class_code"   		    => $grade_date['grade_code'].$i,
				"grade_id"   		    => $grade_id,
				"status"                => 1,
				"create_time"           => date("Y-m-d H:i:s"),
				"update_time"           => "0000-00-00 00:00:00",

				);

				$this->db->do_insert("tbl_class", $info);
				$class_id = $this->db->insert_id();
				// 写入历史班级
				$info = array(
				"class_id"   		    => $class_id,
				"class_box"      		=> $i,
				"class_name"      		=> $grade_date['grade_xname'].$ii.'班',
				"class_xname"      		=> $ii.'班',
				"class_code"   		    => $grade_date['grade_code'].$i,
				"grade_id"   		    => $grade_id,
				"is_now"   		    	=> 1,
				"status"                => 1,
				"create_time"           => date("Y-m-d H:i:s"),
				"update_time"           => "0000-00-00 00:00:00",

				);

				$this->db->do_insert("tbl_class_up", $info);
			}
			// 跳转
			Helper_Client::location("批量添加成功", "index.php?a=student.classlist&grade_id={$grade_id}");
		}

		$this->tpl->assign("grade_date", $grade_date);
		$this->tpl->display('class/class.batch.tpl.php');
	}
	/** 学科分配 （班级）**/
	public function actionclassallot()
	{
		$grade_id      = (int)$this->get->grade_id;
		$class_id      = (int)$this->get->class_id;

		$grade_data 	= $this->model->grade->getInfo($grade_id);
		$class_data 	= $this->model->class->getInfo($class_id);
		$subject_lists 	= $this->model->subject->getAll();

		// 反序列化
		$class_subject = unserialize($class_data['class_subject']);

		if ($_POST){

			$subject_id = $this->post->subject_id;

			foreach ($subject_id as $key => $value){
				$subject_data = $this->model->subject->getInfo($value);
				$row[$value]  = $subject_data['subject_name'];

			}
			$class_subject = serialize($row);

			// 写入数据库
			$info = array(

			"class_subject"   	    => $class_subject,
			"create_time"           => date("Y-m-d H:i:s"),

			);

			$this->db->do_update("tbl_class", $info, "class_id='{$class_id}'");
			// 写入数据库
			$info = array(

			"class_subject"   	    => $class_subject,
			"create_time"           => date("Y-m-d H:i:s"),

			);

			$this->db->do_update("tbl_class_up", $info, "class_id='{$class_id}'");
			// 跳转
			Helper_Client::location("添加成功", "index.php?a=student.classlist&class_id={$class_id}	&grade_id={$grade_id}");
		}

		$this->tpl->assign("grade_data", $grade_data);
		$this->tpl->assign("class_data", $class_data);
		$this->tpl->assign("subject_lists", $subject_lists);
		$this->tpl->display('class/class.allot.tbl.php');

	}
	/** 班级添加 **/
	public function actionclassAdd()
	{
		$grade_id   = (int)$this->get->grade_id;
		$class_id   = (int)$this->get->class_id;

		$grade_data = $this->model->grade->getInfo($grade_id);

		if ($_POST){

			$class_name     	    = $this->post->class_name;
			$class_xname     	    = $this->post->class_xname;
			$class_code    		   	= $this->post->class_code;
			$class_title    		= $this->post->class_title;
			$upc_year    			= $this->post->upc_year;

			// 写入数据库
			$info = array(
			"class_box"      		=> 0,
			"class_name"      		=> $class_name,
			"class_xname"      		=> $class_xname,
			"class_code"   		    => $grade_data['grade_code'].$class_code,
			"grade_id"   		    => $grade_id,
			"class_year"   		    => $upc_year,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",

			);

			$this->db->do_insert("tbl_class", $info);
			$class_id = $this->db->insert_id();
			// 写入班级历史记录
			$info = array(

			"class_name"      		=> $class_name,
			"class_xname"      		=> $class_xname,
			"class_code"   		    => $grade_data['grade_code'].$class_code,
			"class_id"   		    => $class_id,
			"grade_id"   		    => $grade_id,
			"upc_year"   		    => $upc_year,
			"upc_fid"   		    => 0,
			"is_now"   		    	=> 1,
			"status"                => 1,
			"create_time"           => date("Y-m-d H:i:s"),
			"update_time"           => "0000-00-00 00:00:00",

			);
			$this->db->do_insert("tbl_class_up", $info);
			// 跳转
			Helper_Client::location("添加成功", "index.php?a=student.classlist&grade_id={$grade_id}&class_id={$class_id}");
		}

		$this->tpl->assign("grade_id", $grade_id);
		$this->tpl->assign("grade_data", $grade_data);
		$this->tpl->display('class/class.add.tpl.php');
	}
	/** 班级修改 **/
	public function actionclassUpdate()
	{

		$grade_id   = (int)$this->get->grade_id;
		$class_id   = (int)$this->get->class_id;

		$grade_data = $this->model->grade->getInfo($grade_id);
		$class_data = $this->model->class->getInfo($class_id);

		if (empty($grade_data)){
			Helper_Client::alert("年级不存在");
		}

		if ($_POST){

			$class_name    	    	= $this->post->class_name;
			$class_xname    	    	= $this->post->class_xname;
			$class_code    	        = $this->post->class_code;

			// 写入数据库
			$info = array(

			"class_name"      		=> $class_name,
			"class_xname"      		=> $class_xname,
			"class_code"      		=> $class_code,
			"create_time"           => date("Y-m-d H:i:s"),

			);
			$this->db->do_update("tbl_class", $info, "class_id='{$class_id}'");
			// 写入历史记录
			$info = array(

			"class_name"      		=> $class_name,
			"class_xname"      		=> $class_xname,
			"class_code"      		=> $class_code,
			"create_time"           => date("Y-m-d H:i:s"),

			);
			$this->db->do_update("tbl_class_up", $info, "class_id='{$class_id}' AND is_now='1'");

			// 跳转
			Helper_Client::location("修改成功", "index.php?a=student.classlist&grade_id={$grade_id}&class_id={$class_id}");
		}

		$this->tpl->assign("class_data", $class_data);
		$this->tpl->assign("grade_data", $grade_data);
		$this->tpl->display('class/class.update.tpl.php');
	}

	/** 班级删除 **/
	public function actionclassDel()
	{
		$class_id = $this->get->class_id;
		$grade_id = $this->get->grade_id;
		$this->db->query("DELETE  FROM `tbl_class` WHERE class_id='{$class_id}'");
		$this->db->query("DELETE  FROM `tbl_class_up` WHERE class_id='{$class_id}' AND is_now ='1' ");
		// 删除学生
		$student_lists = $this->model->student->getClassAll($class_id);
		foreach ($student_lists as $key=>$value){

			$info = array(
			"class_id"   		=> '',
			"grade_id"       	=> '',
			"create_time"       => date("Y-m-d H:i:s"),

			);

			$this->db->do_update("tbl_student", $info, "student_id='{$value['student_id']}'");
		}
		// 跳转
		Helper_Client::location("删除成功", "index.php?a=student.classlist&class_id={$class_id}&grade_id={$grade_id}");
	}
	/** ----------------------------------年级升迁 ----------------------------------- **/
	/** 升迁 **/
	public function actionGradeUp()
	{
		$grade_id   = (int)$this->get->grade_id;
		// 当前年级
		$grade_data = $this->model->grade->getinfo($grade_id);
		// 获取升迁代码
		$up_code = $grade_data['grade_code']+1;

		// (判断上年级是否存在 NUll=不存在)
		$grade_up = $this->model->grade->getUpGraduate($up_code);
		if (!empty($grade_up)) {
			Helper_Client::alert("年级存在，请从高年级往低年级升迁");
		}
		if (!empty($grade_data)){
			$upg_year 	= $this->post->upg_year;
			// 通过代码找年级（升迁代码）
			if ($_POST) {
				if (empty($grade_up)) {
					// 获得名称
					$grade_code = $grade_data['grade_code']+1;
					// 上级年级信息
					$grade_one = $this->model->grade->getCode($grade_code);
					$grade_end = $this->model->grade->getGradeUpinfo($grade_id);
					// 修改年级历史记录表当前状态
					$info = array(
					"is_now"      		=> 0,
					);
					$this->db->do_update("tbl_grade_up", $info, "upg_id='{$grade_end['upg_id']}'");

					// 新增年级记录表
					$info = array(

					"grade_id"      		=> $grade_id,
					"grade_name"      		=> $grade_one['grade_name'],
					"grade_xname"      		=> $grade_one['grade_xname'],
					"upg_fid"      			=> $grade_end['upg_id'],
					"grade_code"      		=> $grade_one['grade_code'],
					"is_now"  		    	=> 1,
					"upg_year"  		    => $upg_year,
					"status"                => 1,
					"create_time"           => date("Y-m-d H:i:s"),
					"update_time"           => "0000-00-00 00:00:00",

					);
					$this->db->do_insert("tbl_grade_up", $info);
					//** 班级升迁部分开始**//
					// 年级下所有的班级
					$class_lists = $this->model->class->getListByGrade($grade_id);

					foreach ($class_lists as $key => $value){
						// 查找班级历史记录表-》获取upc_fid
						$class_data = $this->model->class->getInfo($value['class_id']);
						// 改变历史班级记录表的状态（）
						$row = $this->model->class->getClassEnd($value['class_id']);
						$info = array(
						"is_now"      	=> 0,
						);
						$this->db->do_update("tbl_class_up", $info, "upc_id='{$row['upc_id']}'");
						// 取班级代码
						$tow = substr($value['class_code'],1,3);
						$noe = substr($value['class_code'],0,1);
						$noe = $noe+1;
						$class_code = $noe.$tow;

						// 新增年级记录表
						$info = array(

						"class_id"      		=> $value['class_id'],
						"class_name"      		=> $grade_one['grade_xname'].$value['class_xname'],
						"class_xname"      		=> $value['class_xname'],
						"class_code"      		=> $class_code,
						"grade_id"      		=> $grade_id,
						"upc_fid"      			=> $class_data['upc_id'],
						"is_now"  		    	=> 1,
						"upc_year"  		    => $upg_year,
						"status"                => 1,
						"create_time"           => date("Y-m-d H:i:s"),
						"update_time"           => "0000-00-00 00:00:00",

						);

						$this->db->do_insert("tbl_class_up", $info);
					}
					//** 班级升迁部分结束**//
					// 跳转
					Helper_Client::location("升迁成功", "index.php?a=student.gradeList");
				}
			}

		}

		$this->tpl->assign("gtade_data", $gtade_data);
		$this->tpl->display('grade/grade.up.tpl.php');
	}
	/** 毕业 **/
	public function actionGradeUps()
	{
		$grade_id   = (int)$this->get->grade_id;
		// 当前年级
		$grade_data = $this->model->grade->getinfo($grade_id);
		// 获取升迁代码
		$up_code = $grade_data['grade_code']+1;
		
		// (判断上年级是否存在 NUll=不存在)
		$grade_up = $this->model->grade->getUpGraduate($up_code);
		if (!empty($grade_up)) {
			Helper_Client::alert("年级存在，请从高年级往低年级升迁");
		}
		$upg_year 	= $this->post->upg_year;
		// 通过代码找年级（升迁代码）
		if ($_POST) {
			$grade_code = $this->model->grade->getCode($up_code);
			
			if (empty($grade_code)) {

				// 没有更高年级，毕业
				$info = array(

				"grade_id"      		=> $grade_id,
				"grade_name"      		=> $grade_data['grade_name'],
				"grade_xname"      		=> $grade_data['grade_xname'],
				"upg_fid"      			=> $grade_data['upg_id'],
				"grade_code"      		=> $grade_data['grade_code'],
				"upg_graduate"      	=> 1,
				"is_now"  		    	=> 0,
				"upg_year"  		    => $upg_year,
				"status"                => 1,
				"create_time"           => date("Y-m-d H:i:s"),
				"update_time"           => "0000-00-00 00:00:00",

				);
				$this->db->do_insert("tbl_grade_up", $info);
				$info = array(
				"is_now"  		    	=> 0,
				"create_time"           => date("Y-m-d H:i:s"),
				);
				$this->db->do_update("tbl_grade_up", $info, "grade_id='{$grade_id}' AND is_now='1'");
				//** 班级升迁部分开始**//
				// 年级下所有的班级
				$class_lists = $this->model->class->getListByGrade($grade_id);

				foreach ($class_lists as $key => $value){
					// 查找班级历史记录表-》获取upc_fid
					$class_data = $this->model->class->getInfo($value['class_id']);
					// 改变历史班级记录表的状态（）
					$row = $this->model->class->getClassEnd($value['class_id']);
					$info = array(
					"is_now"      	=> 0,
					);
					$this->db->do_update("tbl_class_up", $info, "upc_id='{$row['upc_id']}'");
					// 取班级代码
					$tow = substr($value['class_code'],1,3);
					$noe = substr($value['class_code'],0,1);
					$noe = $noe+1;
					$class_code = $noe.$tow;
					// 新增年级记录表（毕业）
					$info = array(

					"class_id"      		=> $value['class_id'],
					"class_name"      		=> $value['class_name'],
					"class_xname"      		=> $value['class_xname'],
					"class_code"      		=> $class_code,
					"grade_id"      		=> $grade_id,
					"upc_fid"      			=> $class_data['upc_id'],
					"upc_graduate"      	=> 1,
					"is_now"  		    	=> 0,
					"upc_year"  		    => $upg_year,
					"status"                => 1,
					"create_time"           => date("Y-m-d H:i:s"),
					"update_time"           => "0000-00-00 00:00:00",

					);

					$this->db->do_insert("tbl_class_up", $info);
					$info = array(
					"is_now"  		    	=> 0,
					"create_time"           => date("Y-m-d H:i:s"),
					);
					$this->db->do_update("tbl_grade_up", $info, "grade_id='{$grade_id}' AND is_now='1'");
				}
				// 跳转
				Helper_Client::location("毕业", "index.php?a=student.gradeList");
			}

		}

		$this->tpl->assign("gtade_data", $gtade_data);
		$this->tpl->display('grade/grade.up.tpl.php');
	}

	/** ------------------------------二维码------------------------------- **/

	/** 生成二维码列表页 **/
	public function actionQrList()
	{

		$this->tpl->display('student/student.qrlist.tpl.php');
	}

	/** 二维码输出页 **/
	public function actionQrOut()
	{

		// 学号起始
		$no_start = $this->post->no_start;
		$no_end   = $this->post->no_end;

		// 二维码宽高
		$qr_w     = (int)$this->post->qr_w;
		if (empty($qr_w)){
			$qr_w = 500;
		}
		$qr_h     = (int)$this->post->qr_h;
		if (empty($qr_h)){
			$qr_h = 500;
		}

		// 行数列数
		$page_row = $this->post->page_row;
		$page_col = $this->post->page_col;

		// 输出结果
		$student_lists = $this->db->fetchAll("SELECT * FROM `tbl_student` WHERE student_no>='{$no_start}' AND student_no<='{$no_end}' ");

		$this->tpl->assign("qr_w", $qr_w);
		$this->tpl->assign("qr_h", $qr_h);
		$this->tpl->assign("student_lists", $student_lists);
		$this->tpl->display('student/student.qrout.tpl.php');

	}

	/** 学生二维码图片 **/
	public function actionQrPic()
	{
		require_once ("lib/phpqrcode/phpqrcode.php");

		$student_id   = (int)$this->get->student_id;
		$student_data = $this->db->fetchRow("SELECT * FROM `tbl_student` WHERE student_id='{$student_id}' ");


		if (empty($student_data)){
			return true;
		}

		$qr_img               = QR_PATH."/".$student_id.".png";

		// 检测是否图片文件已存在
		if (file_exists($qr_img)){
			header("Content-Type:image/png");

			echo file_get_contents($qr_img );
		}else{

			$friend_url = "http://schoolplat.wangyunw.com/public/index.php?a=student.qrinfo&student_id={$student_id}";

			$errorCorrectionLevel = "H";
			$matrixPointSize      = "16";

			ob_clean();
			// 生成图片到指定路径并在线输出
			QRcode::png($friend_url, $qr_img, $errorCorrectionLevel, $matrixPointSize, 4, true);
		}

		exit();
	}

	public function actionoutput(){
		header("Pragma: public");
		header("Expires: 0");
		header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
		header("Content-Type:application/force-download");
		header("Content-Type:application/vnd.ms-execl");
		header("Content-Type:application/octet-stream");
		header("Content-Type:application/download");

		header("Content-Transfer-Encoding:binary");
		$fname = 'student_in.xls';
		$fpath = TP_PATH."/{$fname}";
		//echo $fpath ; exit;
		// 输出下载文件头s
		header("Content-Disposition: attachment; filename={$fname}");
		// 在线输出
		readfile($fpath);
		//$objWriter->save('php://output');
	}
	/*成绩单*/
	public function actiongrades(){

        $grade_id = $this->user['grade_id'];
        $student_id = $this->user['student_id'];
        /*最近一次考试*/
        $exam = $this->db->fetchRow("SELECT * FROM `tbl_exam` WHERE grade_id = '{$grade_id}' ORDER BY create_time DESC ");
        //var_dump($exam);
        //考试成绩
        $score_lists = $this->db->fetchAll("SELECT * FROM `tbl_score` WHERE exam_id='{$exam['exam_id']}' AND student_id='{$student_id}'");
        foreach ($score_lists as $key=> $value){
            $subject_name = $this->model->subject->getinfo($value['subject_id']);
            $score_lists[$key]['subject_name'] = $subject_name['subject_name'];
        }
        $this->tpl->assign("exam", $exam);
        $this->tpl->assign("score_lists", $score_lists);
        $this->tpl->display('student/m.grades.tpl.php');
    }//历史成绩
    public function actiongradeshistry(){

        $grade_id = $this->user['grade_id'];
        $student_id = $this->user['student_id'];
        /*考试*/
        $exam_lists = $this->db->fetchAll("SELECT * FROM `tbl_exam` WHERE grade_id = '{$grade_id}' ORDER BY create_time DESC ");

        //考试成绩
        foreach ($exam_lists as $k => $v){
        $score_lists = $this->db->fetchAll("SELECT * FROM `tbl_score` WHERE exam_id='{$v['exam_id']}' AND student_id='{$student_id}'");
            foreach ($score_lists as $key=> $value){
                $subject_name = $this->model->subject->getinfo($value['subject_id']);
                $score_lists[$key]['subject_name'] = $subject_name['subject_name'];
            }
            $exam_lists[$k]['sub'] = $score_lists;
        }
        //print_r($exam_lists);
        $this->tpl->assign("exam_lists", $exam_lists);
        $this->tpl->display('student/m.gradeshistry.tpl.php');
    }
}

?>